package com.bluesky.controller;

import com.bluesky.comm.Result;
import com.bluesky.comm.ResultUtils;
import com.bluesky.dto.lesson030.Lesson030UserRegisterRequest;
import com.bluesky.service.lesson030.ILesson030UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/lesson030")
public class Lesson030Controller {

    @Autowired
    private ILesson030UserService lesson030UserService;

    /**
     * 演示：用户注册成功，并发送注册消息
     * @param req
     * @return
     */
    @RequestMapping("/register")
    public Result<String> register(@Validated @RequestBody Lesson030UserRegisterRequest req) {
        return ResultUtils.success(this.lesson030UserService.register(req));
    }

    /**
     * 演示：用户注册的事务中有异常，消息投递会被自动取消
     */
    @RequestMapping("/registerError")
    public Result<String> registerError(@Validated @RequestBody Lesson030UserRegisterRequest req) {
        return ResultUtils.success(this.lesson030UserService.registerError(req));
    }
}
